package main

import "fmt"

func commonAdd() {
	sum := 0
	for i := 0; i < 10; i++ {
		sum += i
	}
	fmt.Println(sum)
}

// Adder 函数式编程,闭包
func Adder() func(int) int {
	num := 0
	return func(v int) int {
		num += v
		return num
	}
}

func callAdder() {
	addr := Adder()
	var res = 0
	for i := 0; i < 10; i++ {
		res = addr(i)
	}

	fmt.Println(res)
}

func main() {
	callAdder()
}
